package com.spring.server;

import com.spring.http.Servlet;

import java.util.ArrayList;
import java.util.List;

/**
 * 简化版，没有路径
 *
 * @author Spring King
 * @date 2021/7/11
 */
public class KingContext {

    private List<KingWrapper> wrappers = new ArrayList<>();


    public List<KingWrapper> getWrappers() {
        return wrappers;
    }

    public void setWrappers(List<KingWrapper> wrappers) {
        this.wrappers = wrappers;
    }

    public void addWrapper(KingWrapper wrapper) {
        getWrappers().add(wrapper);
    }

    public Servlet getServlet(String uri) {
        return getWrappers().stream()
                .filter(kingWrapper -> kingWrapper.match(uri))
                .map(KingWrapper::getServlet)
                .findFirst().orElse(null);
    }
}
